<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - Lua 5.1.5 - src/lobject.c</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - lobject.c</td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">Lua 5.1.5</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">102</td>
            <td class="headerCovTableEntry">115</td>
            <td class="headerCovTableEntryMed">88.7 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2019-06-13 19:44:15</td>
            <td></td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<span class="lineNum">       1 </span>            : /*
<span class="lineNum">       2 </span>            : ** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $
<span class="lineNum">       3 </span>            : ** Some generic functions over Lua objects
<span class="lineNum">       4 </span>            : ** See Copyright Notice in lua.h
<span class="lineNum">       5 </span>            : */
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : #include &lt;ctype.h&gt;
<span class="lineNum">       8 </span>            : #include &lt;stdarg.h&gt;
<span class="lineNum">       9 </span>            : #include &lt;stdio.h&gt;
<span class="lineNum">      10 </span>            : #include &lt;stdlib.h&gt;
<span class="lineNum">      11 </span>            : #include &lt;string.h&gt;
<span class="lineNum">      12 </span>            : 
<span class="lineNum">      13 </span>            : #define lobject_c
<span class="lineNum">      14 </span>            : #define LUA_CORE
<span class="lineNum">      15 </span>            : 
<span class="lineNum">      16 </span>            : #include &quot;lua.h&quot;
<span class="lineNum">      17 </span>            : 
<span class="lineNum">      18 </span>            : #include &quot;ldo.h&quot;
<span class="lineNum">      19 </span>            : #include &quot;lmem.h&quot;
<span class="lineNum">      20 </span>            : #include &quot;lobject.h&quot;
<span class="lineNum">      21 </span>            : #include &quot;lstate.h&quot;
<span class="lineNum">      22 </span>            : #include &quot;lstring.h&quot;
<span class="lineNum">      23 </span>            : #include &quot;lvm.h&quot;
<span class="lineNum">      24 </span>            : 
<span class="lineNum">      25 </span>            : 
<span class="lineNum">      26 </span>            : 
<span class="lineNum">      27 </span>            : const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL};
<span class="lineNum">      28 </span>            : 
<span class="lineNum">      29 </span>            : 
<span class="lineNum">      30 </span>            : /*
<span class="lineNum">      31 </span>            : ** converts an integer to a &quot;floating point byte&quot;, represented as
<span class="lineNum">      32 </span>            : ** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if
<span class="lineNum">      33 </span>            : ** eeeee != 0 and (xxx) otherwise.
<span class="lineNum">      34 </span>            : */
<span class="lineNum">      35 </span><span class="lineCov">       1352 : int luaO_int2fb (unsigned int x) {</span>
<span class="lineNum">      36 </span><span class="lineCov">       1352 :   int e = 0;  /* expoent */</span>
<span class="lineNum">      37 </span><span class="lineCov">       1359 :   while (x &gt;= 16) {</span>
<span class="lineNum">      38 </span><span class="lineCov">          7 :     x = (x+1) &gt;&gt; 1;</span>
<span class="lineNum">      39 </span><span class="lineCov">          7 :     e++;</span>
<span class="lineNum">      40 </span>            :   }
<span class="lineNum">      41 </span><span class="lineCov">       1352 :   if (x &lt; 8) return x;</span>
<span class="lineNum">      42 </span><span class="lineCov">          5 :   else return ((e+1) &lt;&lt; 3) | (cast_int(x) - 8);</span>
<span class="lineNum">      43 </span>            : }
<span class="lineNum">      44 </span>            : 
<span class="lineNum">      45 </span>            : 
<span class="lineNum">      46 </span>            : /* converts back */
<span class="lineNum">      47 </span><span class="lineCov">      13154 : int luaO_fb2int (int x) {</span>
<span class="lineNum">      48 </span><span class="lineCov">      13154 :   int e = (x &gt;&gt; 3) &amp; 31;</span>
<span class="lineNum">      49 </span><span class="lineCov">      13154 :   if (e == 0) return x;</span>
<span class="lineNum">      50 </span><span class="lineCov">          5 :   else return ((x &amp; 7)+8) &lt;&lt; (e - 1);</span>
<span class="lineNum">      51 </span>            : }
<span class="lineNum">      52 </span>            : 
<span class="lineNum">      53 </span>            : 
<span class="lineNum">      54 </span><span class="lineCov">      37125 : int luaO_log2 (unsigned int x) {</span>
<span class="lineNum">      55 </span>            :   static const lu_byte log_2[256] = {
<span class="lineNum">      56 </span>            :     0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
<span class="lineNum">      57 </span>            :     6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
<span class="lineNum">      58 </span>            :     7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
<span class="lineNum">      59 </span>            :     7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
<span class="lineNum">      60 </span>            :     8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
<span class="lineNum">      61 </span>            :     8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
<span class="lineNum">      62 </span>            :     8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
<span class="lineNum">      63 </span>            :     8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
<span class="lineNum">      64 </span>            :   };
<span class="lineNum">      65 </span><span class="lineCov">      37125 :   int l = -1;</span>
<span class="lineNum">      66 </span><span class="lineCov">      37194 :   while (x &gt;= 256) { l += 8; x &gt;&gt;= 8; }</span>
<span class="lineNum">      67 </span><span class="lineCov">      37125 :   return l + log_2[x];</span>
<span class="lineNum">      68 </span>            : 
<span class="lineNum">      69 </span>            : }
<span class="lineNum">      70 </span>            : 
<span class="lineNum">      71 </span>            : 
<span class="lineNum">      72 </span><span class="lineCov">       2310 : int luaO_rawequalObj (const TValue *t1, const TValue *t2) {</span>
<span class="lineNum">      73 </span><span class="lineCov">       2310 :   if (ttype(t1) != ttype(t2)) return 0;</span>
<span class="lineNum">      74 </span><span class="lineCov">       1362 :   else switch (ttype(t1)) {</span>
<span class="lineNum">      75 </span><span class="lineCov">          1 :     case LUA_TNIL:</span>
<span class="lineNum">      76 </span><span class="lineCov">          1 :       return 1;</span>
<span class="lineNum">      77 </span><span class="lineCov">         55 :     case LUA_TNUMBER:</span>
<span class="lineNum">      78 </span><span class="lineCov">         55 :       return luai_numeq(nvalue(t1), nvalue(t2));</span>
<span class="lineNum">      79 </span><span class="lineCov">        104 :     case LUA_TBOOLEAN:</span>
<span class="lineNum">      80 </span><span class="lineCov">        104 :       return bvalue(t1) == bvalue(t2);  /* boolean true must be 1 !! */</span>
<span class="lineNum">      81 </span><span class="lineCov">        474 :     case LUA_TLIGHTUSERDATA:</span>
<span class="lineNum">      82 </span><span class="lineCov">        474 :       return pvalue(t1) == pvalue(t2);</span>
<span class="lineNum">      83 </span><span class="lineCov">        728 :     default:</span>
<span class="lineNum">      84 </span>            :       lua_assert(iscollectable(t1));
<span class="lineNum">      85 </span><span class="lineCov">        728 :       return gcvalue(t1) == gcvalue(t2);</span>
<span class="lineNum">      86 </span>            :   }
<span class="lineNum">      87 </span>            : }
<span class="lineNum">      88 </span>            : 
<span class="lineNum">      89 </span>            : 
<span class="lineNum">      90 </span><span class="lineCov">       3191 : int luaO_str2d (const char *s, lua_Number *result) {</span>
<span class="lineNum">      91 </span>            :   char *endptr;
<span class="lineNum">      92 </span><span class="lineCov">       3191 :   *result = lua_str2number(s, &amp;endptr);</span>
<span class="lineNum">      93 </span><span class="lineCov">       3191 :   if (endptr == s) return 0;  /* conversion failed */</span>
<span class="lineNum">      94 </span><span class="lineCov">       3167 :   if (*endptr == 'x' || *endptr == 'X')  /* maybe an hexadecimal constant? */</span>
<span class="lineNum">      95 </span><span class="lineNoCov">          0 :     *result = cast_num(strtoul(s, &amp;endptr, 16));</span>
<span class="lineNum">      96 </span><span class="lineCov">       3167 :   if (*endptr == '\0') return 1;  /* most common case */</span>
<span class="lineNum">      97 </span><span class="lineCov">          9 :   while (isspace(cast(unsigned char, *endptr))) endptr++;</span>
<span class="lineNum">      98 </span><span class="lineCov">          5 :   if (*endptr != '\0') return 0;  /* invalid trailing characters? */</span>
<span class="lineNum">      99 </span><span class="lineCov">          2 :   return 1;</span>
<span class="lineNum">     100 </span>            : }
<span class="lineNum">     101 </span>            : 
<span class="lineNum">     102 </span>            : 
<span class="lineNum">     103 </span>            : 
<span class="lineNum">     104 </span><span class="lineCov">       5675 : static void pushstr (lua_State *L, const char *str) {</span>
<span class="lineNum">     105 </span><span class="lineCov">       5675 :   setsvalue2s(L, L-&gt;top, luaS_new(L, str));</span>
<span class="lineNum">     106 </span><span class="lineCov">       5675 :   incr_top(L);</span>
<span class="lineNum">     107 </span><span class="lineCov">       5675 : }</span>
<span class="lineNum">     108 </span>            : 
<span class="lineNum">     109 </span>            : 
<span class="lineNum">     110 </span>            : /* this function handles only `%d', `%c', %f, %p, and `%s' formats */
<span class="lineNum">     111 </span><span class="lineCov">       1690 : const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {</span>
<span class="lineNum">     112 </span><span class="lineCov">       1690 :   int n = 1;</span>
<span class="lineNum">     113 </span><span class="lineCov">       1690 :   pushstr(L, &quot;&quot;);</span>
<span class="lineNum">     114 </span><span class="lineCov">       2654 :   for (;;) {</span>
<span class="lineNum">     115 </span><span class="lineCov">       4344 :     const char *e = strchr(fmt, '%');</span>
<span class="lineNum">     116 </span><span class="lineCov">       4344 :     if (e == NULL) break;</span>
<span class="lineNum">     117 </span><span class="lineCov">       2654 :     setsvalue2s(L, L-&gt;top, luaS_newlstr(L, fmt, e-fmt));</span>
<span class="lineNum">     118 </span><span class="lineCov">       2654 :     incr_top(L);</span>
<span class="lineNum">     119 </span><span class="lineCov">       2654 :     switch (*(e+1)) {</span>
<span class="lineNum">     120 </span><span class="lineCov">       2263 :       case 's': {</span>
<span class="lineNum">     121 </span><span class="lineCov">       2263 :         const char *s = va_arg(argp, char *);</span>
<span class="lineNum">     122 </span><span class="lineCov">       2263 :         if (s == NULL) s = &quot;(null)&quot;;</span>
<span class="lineNum">     123 </span><span class="lineCov">       2263 :         pushstr(L, s);</span>
<span class="lineNum">     124 </span><span class="lineCov">       2263 :         break;</span>
<span class="lineNum">     125 </span>            :       }
<span class="lineNum">     126 </span><span class="lineCov">         16 :       case 'c': {</span>
<span class="lineNum">     127 </span>            :         char buff[2];
<span class="lineNum">     128 </span><span class="lineCov">         16 :         buff[0] = cast(char, va_arg(argp, int));</span>
<span class="lineNum">     129 </span><span class="lineCov">         16 :         buff[1] = '\0';</span>
<span class="lineNum">     130 </span><span class="lineCov">         16 :         pushstr(L, buff);</span>
<span class="lineNum">     131 </span><span class="lineCov">         16 :         break;</span>
<span class="lineNum">     132 </span>            :       }
<span class="lineNum">     133 </span><span class="lineCov">        359 :       case 'd': {</span>
<span class="lineNum">     134 </span><span class="lineCov">        359 :         setnvalue(L-&gt;top, cast_num(va_arg(argp, int)));</span>
<span class="lineNum">     135 </span><span class="lineCov">        359 :         incr_top(L);</span>
<span class="lineNum">     136 </span><span class="lineCov">        359 :         break;</span>
<span class="lineNum">     137 </span>            :       }
<span class="lineNum">     138 </span><span class="lineNoCov">          0 :       case 'f': {</span>
<span class="lineNum">     139 </span><span class="lineNoCov">          0 :         setnvalue(L-&gt;top, cast_num(va_arg(argp, l_uacNumber)));</span>
<span class="lineNum">     140 </span><span class="lineNoCov">          0 :         incr_top(L);</span>
<span class="lineNum">     141 </span><span class="lineNoCov">          0 :         break;</span>
<span class="lineNum">     142 </span>            :       }
<span class="lineNum">     143 </span><span class="lineCov">         13 :       case 'p': {</span>
<span class="lineNum">     144 </span>            :         char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */
<span class="lineNum">     145 </span><span class="lineCov">         13 :         sprintf(buff, &quot;%p&quot;, va_arg(argp, void *));</span>
<span class="lineNum">     146 </span><span class="lineCov">         13 :         pushstr(L, buff);</span>
<span class="lineNum">     147 </span><span class="lineCov">         13 :         break;</span>
<span class="lineNum">     148 </span>            :       }
<span class="lineNum">     149 </span><span class="lineCov">          3 :       case '%': {</span>
<span class="lineNum">     150 </span><span class="lineCov">          3 :         pushstr(L, &quot;%&quot;);</span>
<span class="lineNum">     151 </span><span class="lineCov">          3 :         break;</span>
<span class="lineNum">     152 </span>            :       }
<span class="lineNum">     153 </span><span class="lineNoCov">          0 :       default: {</span>
<span class="lineNum">     154 </span>            :         char buff[3];
<span class="lineNum">     155 </span><span class="lineNoCov">          0 :         buff[0] = '%';</span>
<span class="lineNum">     156 </span><span class="lineNoCov">          0 :         buff[1] = *(e+1);</span>
<span class="lineNum">     157 </span><span class="lineNoCov">          0 :         buff[2] = '\0';</span>
<span class="lineNum">     158 </span><span class="lineNoCov">          0 :         pushstr(L, buff);</span>
<span class="lineNum">     159 </span><span class="lineNoCov">          0 :         break;</span>
<span class="lineNum">     160 </span>            :       }
<span class="lineNum">     161 </span>            :     }
<span class="lineNum">     162 </span><span class="lineCov">       2654 :     n += 2;</span>
<span class="lineNum">     163 </span><span class="lineCov">       2654 :     fmt = e+2;</span>
<span class="lineNum">     164 </span>            :   }
<span class="lineNum">     165 </span><span class="lineCov">       1690 :   pushstr(L, fmt);</span>
<span class="lineNum">     166 </span><span class="lineCov">       1690 :   luaV_concat(L, n+1, cast_int(L-&gt;top - L-&gt;base) - 1);</span>
<span class="lineNum">     167 </span><span class="lineCov">       1690 :   L-&gt;top -= n;</span>
<span class="lineNum">     168 </span><span class="lineCov">       1690 :   return svalue(L-&gt;top - 1);</span>
<span class="lineNum">     169 </span>            : }
<span class="lineNum">     170 </span>            : 
<span class="lineNum">     171 </span>            : 
<span class="lineNum">     172 </span><span class="lineCov">        289 : const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {</span>
<span class="lineNum">     173 </span>            :   const char *msg;
<span class="lineNum">     174 </span>            :   va_list argp;
<span class="lineNum">     175 </span><span class="lineCov">        289 :   va_start(argp, fmt);</span>
<span class="lineNum">     176 </span><span class="lineCov">        289 :   msg = luaO_pushvfstring(L, fmt, argp);</span>
<span class="lineNum">     177 </span><span class="lineCov">        289 :   va_end(argp);</span>
<span class="lineNum">     178 </span><span class="lineCov">        289 :   return msg;</span>
<span class="lineNum">     179 </span>            : }
<span class="lineNum">     180 </span>            : 
<span class="lineNum">     181 </span>            : 
<span class="lineNum">     182 </span><span class="lineCov">        377 : void luaO_chunkid (char *out, const char *source, size_t bufflen) {</span>
<span class="lineNum">     183 </span><span class="lineCov">        377 :   if (*source == '=') {</span>
<span class="lineNum">     184 </span><span class="lineCov">         65 :     strncpy(out, source+1, bufflen);  /* remove first char */</span>
<span class="lineNum">     185 </span><span class="lineCov">         65 :     out[bufflen-1] = '\0';  /* ensures null termination */</span>
<span class="lineNum">     186 </span>            :   }
<span class="lineNum">     187 </span>            :   else {  /* out = &quot;source&quot;, or &quot;...source&quot; */
<span class="lineNum">     188 </span><span class="lineCov">        312 :     if (*source == '@') {</span>
<span class="lineNum">     189 </span>            :       size_t l;
<span class="lineNum">     190 </span><span class="lineCov">        276 :       source++;  /* skip the `@' */</span>
<span class="lineNum">     191 </span><span class="lineCov">        276 :       bufflen -= sizeof(&quot; '...' &quot;);</span>
<span class="lineNum">     192 </span><span class="lineCov">        276 :       l = strlen(source);</span>
<span class="lineNum">     193 </span><span class="lineCov">        276 :       strcpy(out, &quot;&quot;);</span>
<span class="lineNum">     194 </span><span class="lineCov">        276 :       if (l &gt; bufflen) {</span>
<span class="lineNum">     195 </span><span class="lineNoCov">          0 :         source += (l-bufflen);  /* get last part of file name */</span>
<span class="lineNum">     196 </span><span class="lineNoCov">          0 :         strcat(out, &quot;...&quot;);</span>
<span class="lineNum">     197 </span>            :       }
<span class="lineNum">     198 </span><span class="lineCov">        276 :       strcat(out, source);</span>
<span class="lineNum">     199 </span>            :     }
<span class="lineNum">     200 </span>            :     else {  /* out = [string &quot;string&quot;] */
<span class="lineNum">     201 </span><span class="lineCov">         36 :       size_t len = strcspn(source, &quot;\n\r&quot;);  /* stop at first newline */</span>
<span class="lineNum">     202 </span><span class="lineCov">         36 :       bufflen -= sizeof(&quot; [string \&quot;...\&quot;] &quot;);</span>
<span class="lineNum">     203 </span><span class="lineCov">         36 :       if (len &gt; bufflen) len = bufflen;</span>
<span class="lineNum">     204 </span><span class="lineCov">         36 :       strcpy(out, &quot;[string \&quot;&quot;);</span>
<span class="lineNum">     205 </span><span class="lineCov">         36 :       if (source[len] != '\0') {  /* must truncate? */</span>
<span class="lineNum">     206 </span><span class="lineCov">         10 :         strncat(out, source, len);</span>
<span class="lineNum">     207 </span><span class="lineCov">         10 :         strcat(out, &quot;...&quot;);</span>
<span class="lineNum">     208 </span>            :       }
<span class="lineNum">     209 </span>            :       else
<span class="lineNum">     210 </span><span class="lineCov">         26 :         strcat(out, source);</span>
<span class="lineNum">     211 </span><span class="lineCov">         36 :       strcat(out, &quot;\&quot;]&quot;);</span>
<span class="lineNum">     212 </span>            :     }
<span class="lineNum">     213 </span>            :   }
<span class="lineNum">     214 </span><span class="lineCov">        377 : }</span>
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.13</a></td></tr>
  </table>
  <br>

</body>
</html>
